<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    	$this->assign("title","红满堂社区在任管理人员");
    	$this->display();
    	
    }
    public function login(){
    	require './ucenter/config.inc.php';
		require './ucenter/uc_client/client.php';
		
		if(IS_POST){
			$username=I('username');
			$password=(I('password'));
			//先从数据库取密码，如果取不到，则访问论坛
			$userList=M('userlist');
			if(md5($password)==$userList->where("username=$username")->getField('password')){
				session('uid',$uid);
				session('username',$username);
				$this->success( "登录成功",U("Index/index"));
			}else {
				//访问论坛取密码
				list($uid, $username, $password, $email) = uc_user_login($username, $password);
				if($uid > 0) {
					//查有此人，则查其是否有进入系统的权限。非管理层或者非灵魂人物无法进入系统

					define("GHOST_GROUPID", "灵魂人员的groupid");//替换“灵魂人员的groupid 注意用string类型”

					$user=getUser($uid);
					if($user['adminid']=="0"&&$user['groupid']!=GHOST_GROUPID){
						$this->error("对不起，你不是论坛内部人员，无法登录系统");
						//dump($user);
					}else {
						session('uid',$uid);
						session('username',$username);
						//保存密码到本地数据库中
						$where['username']=$username;
						$data['password']=md5($password);
						$userList->where($where)->save($data);
						$this->success( "登录成功",U("Index/index"));
					}
				} else if($uid == -1) {
					echo '用户不存在,或者被删除';
				} else if($uid == -2) {
					echo '密码错';
				} else {
					echo '未定义';
				}
			}
		}
			
    }
}